﻿using MediatR;
using System;
using W.Device.API.Application.Command;
using W.Device.Repository.Interface;

namespace W.Device.API.Application.CommandHandlder
{
    public class DeviceAddCommandHandler : IRequestHandler<DeviceAddCommand, int>
    {
        private readonly IDeviceRepository deviceRepository;

        public DeviceAddCommandHandler(IDeviceRepository deviceRepository)
        {
            this.deviceRepository = deviceRepository;
        }

        public async Task<int> Handle(DeviceAddCommand request, CancellationToken cancellationToken)
        {
            request.IsDelete = false;
            return await deviceRepository.AddAsync(new Domain.DevicesInfo() { DeviceId =request.DeviceId, DeviceNo=request.DeviceNo, DeviceName=request.DeviceName, DeviceAccreNo=request.DeviceAccreNo, IsAccre=request.IsAccre, DeviceStatus=request.DeviceStatus, DeviceRemarks=request.DeviceRemarks, CreateName=request.CreateName, CreateTime=request.CreateTime, UpdateName=request.UpdateName, UpdateTime=request.UpdateTime, DeleteName=request.DeleteName, DeleteTime=request.DeleteTime, IsDelete=request.IsDelete });
        }
    }
}
